import { queryAccount } from '@/services/account';
const AccountModel = {
  namespace: 'account',
  state: {
    accountList: [],
  },
  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(queryAccount);
      yield put({
        type: 'save',
        payload: response,
      });
    },

    *fetchAccount(_, { call, put }) {
      const response = yield call(queryAccount);
      console.log('--->dispath');
      console.log(response);
      yield put({
        type: 'saveAccountList',
        payload: response.data.list,
      });
    },
  },
  reducers: {
    saveAccountList(state, action) {
      return { ...state, accountList: action.payload || {} };
    },

    changeNotifyCount(
      state = {
        accountList: {},
      },
      action,
    ) {
      return {
        ...state,
        accountList: {
          ...state.accountList,
          notifyCount: action.payload.totalCount,
          unreadCount: action.payload.unreadCount,
        },
      };
    },
  },
};
export default AccountModel;
